package com.sjh.lib_app.statusMananger.defWidget

import android.content.Context
import android.view.Gravity
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.sjh.lib_app.statusMananger.StatusManager
import com.sjh.lib_app.statusMananger.StatusView
import com.sjh.lib_app.R
import com.sjh.lib_app.utils.dip

/**
 * explain : 这是数据列表里面无数据的加载占位图
 * author : SunJH
 * data : 2020/3/28
 */
class NoDataStatusView(val iconRes: Int = -1) : StatusView() {
    companion object {
        const val LOAD_NODATA_RELOAD = "NoDataStatusView"
    }

    override fun createView(context: Context, statusManager: StatusManager): View {
        return LinearLayout(context).apply {

            orientation = LinearLayout.VERTICAL
            layoutParams = ViewGroup.LayoutParams(-1, -1)
            gravity = Gravity.CENTER

            val img = ImageView(context)
            val tv = TextView(context)
            tvMessage = tv
            img.apply {
                layoutParams = LinearLayout.LayoutParams(dip(175), dip(125))
                setImageResource(if (iconRes == -1) R.drawable.app_bg_no_data else iconRes)
            }
            tv.apply {
                layoutParams = LinearLayout.LayoutParams(-2, -2).apply {
                    topMargin = dip(11)
                }
                text = defaultEmptyMsg
                setTextColor(context.getColor(R.color.app_font_999999))
            }
            addView(img)
            addView(tv)
            setOnClickListener { statusManager.setOnClickEvent(LOAD_NODATA_RELOAD) }
        }
    }
}